//
//  RequireDetailController.m
//  SSB
//
//  Created by Lyn on 16/9/24.
//  Copyright © 2016年 TNT. All rights reserved.
//
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define ScreenScale (ScreenWidth / 375.f)


#import "RequireDetailController.h"
#import "RequireInfoView.h"
#import "RequireServerModel.h"
#import "RequireServerInfoView.h"
#import "UIView+PFAddtion.h"
#import "UIColor+GDBAddtion.h"
#import "MTChatViewController.h"


@interface RequireDetailController ()

@property (nonatomic, weak) UIScrollView *scrollView;

@property (nonatomic, weak) UIView *topView;

@property (nonatomic, weak) UIView *middleView;

@property (nonatomic, weak) UIView *belowTableView;

@property (nonatomic, weak) UILabel *serverCountLabel;

@end

@implementation RequireDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUp];
    [self initNavigation];
}

- (void)setUp {
    self.navigationController.navigationBar.translucent = NO;
    
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.f, 0.f, ScreenWidth, ScreenHeight - 64.f)];
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.backgroundColor = [UIColor pf_colorWithHexString:@"f7f7f7"];
    [self.view addSubview:scrollView];
    self.scrollView = scrollView;
    
    [self setTopView];
    [self setMiddleView];
    [self setBelowView];
}

#pragma --mark 布局
- (void)setTopView {
    self.title = @"有求详情";
    self.view.backgroundColor = [UIColor pf_colorWithHexString:@"f7f7f7"];
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0.f, 0.f,ScreenWidth , 162 * ScreenScale)];
    topView.backgroundColor = [UIColor whiteColor];
    self.topView = topView;
    UIImageView *titleImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:self.titleImageName]];
    titleImageView.frame = CGRectMake(ScreenWidth / 2.f - 25.5f, 29.f *ScreenScale, 51.f, 51.f);
    [topView addSubview:titleImageView];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.f, titleImageView.bottom + 14.f * ScreenScale, ScreenWidth, 15.f)];
    titleLabel.text = self.titleStr;
    titleLabel.font = [UIFont systemFontOfSize:15.f];
    [titleLabel sizeToFit];
    titleLabel.textColor = [UIColor pf_colorWithHexString:@"333333"];
    titleLabel.centerX = titleImageView.centerX;
    [topView addSubview:titleLabel];
    
    UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.f, titleLabel.bottom + 14.f * ScreenScale, ScreenWidth, 15.f)];
    timeLabel.text = @"11天后过期";/*假数据*/
    timeLabel.font = [UIFont fontWithName:@"STHeitiSC-Light" size:12.f];
    [timeLabel sizeToFit];
    timeLabel.textColor = [UIColor pf_colorWithHexString:@"888888"];
    timeLabel.centerX = titleImageView.centerX;
    [topView addSubview:timeLabel];

    self.scrollView.contentSize =CGSizeMake(ScreenWidth, topView.bottom);
    [self.scrollView addSubview:topView];
    NSLog(@"%@",NSStringFromCGSize(self.scrollView.contentSize));

}

- (void)setMiddleView {
    UIView *middleView = [[UIView alloc]initWithFrame:CGRectMake(0.f, self.topView.bottom + 10.f, ScreenWidth, 153.f)];
    middleView.backgroundColor = [UIColor whiteColor];
    self.middleView = middleView;
    
    RequireInfoView *startTimeView = [[RequireInfoView alloc]initWithIconName:@"require_icon_time" titleName:@"预约时间" containStr:@"2016-09-05"];
    startTimeView.frame = CGRectMake(0.f, 0.f, ScreenWidth / 2.f - 0.5, 51.f);
    [middleView addSubview:startTimeView];
    
    RequireInfoView *endTimeView = [[RequireInfoView alloc]initWithIconName:@"require_icon_expiration_time" titleName:@"过期时间" containStr:@"2016-09-19"];
    endTimeView.frame = CGRectMake(ScreenWidth / 2.f + 0.5f, 0.f, ScreenWidth / 2.f - 0.5, 51.f);
    [middleView addSubview:endTimeView];
    
    UIView *viewLine = [[UIView alloc]initWithFrame:CGRectMake(ScreenWidth / 2.f - 0.5f, 11.f, 1.f, 29.f)];
    viewLine.backgroundColor = [UIColor pf_colorWithHexString:@"f7f7f7"];
    [middleView addSubview:viewLine];
    
    RequireInfoView *areaView = [[RequireInfoView alloc]initWithIconName:@"require_icon_place" titleName:@"预约地点" containStr:@"广东省深圳市罗湖区"];
    areaView.frame = CGRectMake(0.f, 51.f, ScreenWidth, 51.f);
    [middleView addSubview:areaView];
    
    RequireInfoView *otherNeedView = [[RequireInfoView alloc]initWithIconName:@"require_icon_other" titleName:@"其他需求" containStr:@"无"];
    otherNeedView.frame = CGRectMake(0.f, 102.f, ScreenWidth / 2.f - 0.5, 51.f);
    [middleView addSubview:otherNeedView];

    self.scrollView.contentSize =CGSizeMake(ScreenWidth, middleView.bottom);
    [self.scrollView addSubview:middleView];
    NSLog(@"%@",NSStringFromCGSize(self.scrollView.contentSize));

}

- (void)setBelowView {
    /*预计有接口获取model*/
    /*假数据*/
    RequireServerModel *model = [[RequireServerModel alloc]init];
    model.serverPrice = @"150/小时";
    model.serverName = @"奔跑的罗拉";
    model.serverLevel = @"V12";
    model.isIDCer = YES;
    model.isPhoneCer = YES;
    model.isSkillCer = YES;
    
    NSArray *modelArr = @[model,model,model];
    
    UIView *belowView = [[UIView alloc]initWithFrame:CGRectMake(0.f, self.middleView.bottom, ScreenWidth, 50.f + modelArr.count * 135.f)];
    belowView.backgroundColor = [UIColor pf_colorWithHexString:@"#f7f7f7"];
    
    UIView *viewLine = [[UIView alloc]initWithFrame:CGRectMake(10.f, 24.5f, ScreenWidth - 20.f, 1.f)];
    viewLine.backgroundColor = [UIColor pf_colorWithHexString:@"#e9e9e9"];
    [belowView addSubview:viewLine];
    
    UILabel *serverCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(0.f, 0.f, 180.f, 13.f)];
    serverCountLabel.text = [NSString stringWithFormat:@"已有%ld位服务者应邀",modelArr.count];
    serverCountLabel.center = viewLine.center;
    serverCountLabel.backgroundColor = [UIColor pf_colorWithHexString:@"#f7f7f7"];
    [belowView addSubview:serverCountLabel];
    self.serverCountLabel = serverCountLabel;
    
    for (int i = 0; i < modelArr.count; i++) {
        RequireServerInfoView * requireInfoView = [[RequireServerInfoView alloc]init];
        requireInfoView.frame = CGRectMake(0.f, 50.f + 135.f *i, ScreenWidth, 135.f);
        requireInfoView.model = modelArr[i];
        [belowView addSubview:requireInfoView];
    }
    
    [self.scrollView addSubview:belowView];
    self.scrollView.contentSize = CGSizeMake(ScreenWidth, belowView.bottom + 20.f);
    NSLog(@"%@",NSStringFromCGSize(self.scrollView.contentSize));
    
    
    
    
}


-(void)initNavigation {
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSFontAttributeName] = [UIFont boldSystemFontOfSize:17];
    attr[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:attr];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:UIColorFromRGB(0x45c75a)]  forBarMetrics:UIBarMetricsDefault];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"news"] highImage:[UIImage imageNamed:@"news_gray"] target:self action:@selector(chatClick)];
    self.navigationItem.title = @"有求详情";
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"back"] highImage:[UIImage imageNamed:@"back anxia"] target:self action:@selector(backClick)];
}

-(void)chatClick {
    MTChatViewController *vc = [MTChatViewController shareChatViewController];
    [self.navigationController pushViewController:vc animated:YES];
    NSLog(@"one----%@",vc);
    
}

-(void)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}
@end
